home *** CD-ROM | disk | FTP | other *** search
/ ftp.cs.arizona.edu / ftp.cs.arizona.edu.tar / ftp.cs.arizona.edu / icon / newsgrp / group93b.txt / 000086_icon-group-sender _Fri May 14 11:47:26 1993.msg < prev    next >
Internet Message Format  |  1993-06-16  |  2KB

  1. Received: by cheltenham.cs.arizona.edu; Fri, 14 May 1993 10:04:50 MST
  2. Date: Fri, 14 May 93 11:47:26 CDT
  3. From: John David Stone <stone@HILBERT.math.grin.edu>
  4. Message-Id: <9305141647.AA24170@HILBERT.MATH.GRIN.EDU>
  5. To: sboisen@bbn.com
  6. Cc: icon-group@cs.arizona.edu
  7. In-Reply-To: Sean Boisen's message of Fri, 14 May 93 09:46:40 -0400 <9305141346.AA10725@sanborn.bbn.com>
  8. Subject: string stripping
  9. Status: R
  10. Errors-To: icon-group-errors@cs.arizona.edu
  11.  
  12.         Sean Boysen asks:
  13.  
  14. >           ... i have a string and i want to strip out certain characters
  15. >  (internal ones, so trim won't do it) ... am i missing some more
  16. >  idiomatic way to express this? Note there's two parts that i perceive as
  17. >  clunky: the testing of whether c is in badchars (i suppose you could
  18. >  make badchars a string and use find instead), and the control structure
  19. >  with explicit generation and assignment to a new string.
  20.  
  21.         Explicit assignment is not a stylistic defect, since Icon is _not_
  22. going to do in-place updating of the original string even if you use the
  23. same variable name.  New storage is going to be allocated for the result of
  24. the stripping no matter what.  However, it would be nice to break off
  25. long sequences of goodchars instead of inspecting them singly; the
  26. predefined upto procedure is the winning way to do this.
  27.  
  28.         String scanning can be used to avoid the other problem:
  29.  
  30.             bare := ""
  31.             badchars := '-.'
  32.             full ? {
  33.                 while bare ||:= tab(upto(badchars)) do
  34.                     move (1)
  35.                 bare ||:= tab(0)
  36.             }
  37.  
  38. Or in English:  Scan through the value of full, up to the next position
  39. occupied by a badchar.  Break off the part you've just scanned over and
  40. append it to the value of bare.  Advance one position to get past the
  41. badchar.  Repeat until there are no more badchars in the subject.  Then
  42. scan to the end and append what you've just scanned over to the value of
  43. bare.
  44.  
  45. ------  John David Stone - Lecturer in Computer Science and Philosophy  -----
  46. --------------  Manager of the Mathematics Local-Area Network  --------------
  47. --------------  Grinnell College - Grinnell, Iowa 50112 - USA  --------------
  48. --------  stone@math.grin.edu - (515) 269-3181 - stone@grin1.bitnet  --------
  49.